package com.xiaoge;

import com.xiaoge.entity.SecurityUserDetails;
import com.xiaoge.mapper.SysUserMapper;
import com.xiaoge.auth.JwtTokenUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest(classes = {mainApplication.class})
@RunWith(SpringRunner.class)
public class sysusertest {
    @Autowired(required=true)
    private UserDetailsService UserDetailsServiceImpl;
    @Autowired(required=true)
    private SysUserMapper sysUserMapper;
    @Autowired
    private JwtTokenUtil JwtTokenUtil;
    @Autowired
    private SecurityUserDetails SecurityUserDetails;
    @Test
    public void loadUserByUsername(){
        System.out.println(UserDetailsServiceImpl.getClass());
        UserDetails UserDetails = UserDetailsServiceImpl.loadUserByUsername("xiaoge");
        System.out.println(UserDetails.getPassword());
        System.out.println(UserDetails.getAuthorities());
        System.out.println(sysUserMapper.getRoleCodeByUserName("xiaoge"));
    }
    @Test
    public void test(){
        SecurityUserDetails.setId(1);
        SecurityUserDetails.setUsername("张三");
        SecurityUserDetails.setPassword("123");
        String token = JwtTokenUtil.generateToken(SecurityUserDetails);
        System.out.println(token);
    }

    @Test
    public void test1(){
        String token = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ4aWFvZ2UiLCJjcmVhdGVkIjoxNjE0ODQzMjIyOTY4LCJleHAiOjE2MjIwNDMyMjJ9.VGN3h7e9LO-X8nULQvb9H1F0gQf976BCnOx-u4TBlIs0GfEwUfZjk3a1yuCzbTfegHfKgu13N192fVcshCXGNQ";
        String username= JwtTokenUtil.getUserNameFromToken(token);
        System.out.println(username);
    }


}
